module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/', // 打包配置，解决页面空白の配置方案。
  devServer: {
    port: 8008
    // proxy: {
    //     '/api': {
    //         target: 'https://api.zhanhongzhu.top',
    //         changeOrigin: true,
    //         pathRewrite: {
    //             '^/api': '/api'
    //         }
    //     }
    // }
  },
  // 配置webpack
  configureWebpack: config => {
    let isProduction = 1;
    if (isProduction) {
      // 开启分离js
      config.optimization = {
        runtimeChunk: 'single',
        splitChunks: {
          chunks: 'all',
          maxInitialRequests: Infinity,
          minSize: 20000,
          cacheGroups: {
            vendor: {
              test: /[\\/]node_modules[\\/]/,
              name(module) {
                // get the name. E.g. node_modules/packageName/not/this/part.js
                // or node_modules/packageName
                const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
                // npm package names are URL-safe, but some servers don't like @ symbols
                return `npm.${packageName.replace('@', '')}`
              }
            }
          }
        }
      };
    }
  }
}
